/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.demo.widget;

import com.meis.widget.utils.DensityUtil;
import com.meis.widget.utils.PixelUtil;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * 单元测试
 */
public class ExampleOhosTest {
    private Context context;

    /**
     * 测试前置
     */
    @Before
    public void setUp() {
        context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        PixelUtil.initContext(context);
    }

    /**
     * 测试DensityUtil.dp2px()
     */
    @Test
    public void densityUtilDp2px() {
        int dpValue = 10;
        int px = DensityUtil.dp2px(context, dpValue);
        Assert.assertEquals((int) (dpValue * 3 + 0.5), px);
    }

    /**
     * 测试DensityUtil.getScreenHeight()
     */
    @Test
    public void densityUtilGetScreenHeight() {
        int px = DensityUtil.getScreenHeight(context);
        Assert.assertNotNull(px);
    }

    /**
     * 测试PixelUtil.getMax()
     */
    @Test
    public void PixelUtilGetMax() {
        int max = PixelUtil.getMax(1, 2, 7, 4, 5);
        Assert.assertEquals(max, 7);
    }

    /**
     * 测试PixelUtil.InitContext()
     */
    @Test
    public void PixelUtilInitContext() {
        Assert.assertNotNull(PixelUtil.getDisplay());
    }

    /**
     * 测试PixelUtil.screenWidth()
     */
    @Test
    public void PixelUtilScreenWidth() {
        int i = PixelUtil.screenWidth();
        Assert.assertNotEquals(i, 0);
    }

    /**
     * 测试PixelUtil.screenHeight()
     */
    @Test
    public void PixelUtilScreenHeight() {
        int i = PixelUtil.screenHeight();
        Assert.assertNotEquals(i, 0);
    }
}